﻿using System;
using static GlobalField;
public class GlobalField_Read 
{
	 public static tagDataDescribe Read_tagDataDescribe(byte[] bytes) 
	 {
		 // Marshal.SizeOf(tagDataDescribe)=4,Pack=2
		 tagDataDescribe obj = new tagDataDescribe();
		 int SizeConst = 0; 
		 int index = 0; 
		 obj.wDataSize=BitConverter.ToUInt16(bytes , 0);
		 obj.wDataDescribe=BitConverter.ToUInt16(bytes , 2);
		 return obj;
	 }
	 public static Byte[] Read_ByteArray(byte[] bytes, int index , int SizeConst)
	 {
		 Byte[] arr = new Byte[SizeConst];
		 for (int i = 0;i<SizeConst; i++)
		 {
			 arr[i] = bytes[index];
			 index = index + 1;
		 }
		 return arr;
	 }
	 public static IPC_Head Read_IPC_Head(byte[] bytes) 
	 {
		 // Marshal.SizeOf(IPC_Head)=56,Pack=8
		 IPC_Head obj = new IPC_Head();
		 int SizeConst = 0; 
		 int index = 0; 

		 byte[] bytes_desc = new byte[4];
		 Array.Copy(bytes, 0, bytes_desc , 0, 4);
		 obj.desc= Read_tagDataDescribe(bytes_desc);
		 obj.wVersion=BitConverter.ToUInt16(bytes , 4);
		 obj.wRoomID=BitConverter.ToUInt16(bytes , 6);
		 obj.wDataSize=BitConverter.ToUInt16(bytes , 8);
		 obj.wMainCmdID=BitConverter.ToUInt32(bytes , 12);
		 obj.wSubCmdID=BitConverter.ToInt64(bytes , 16);
		 SizeConst = 32;
		 index = 24;
		 obj.szTypeName= Read_ByteArray(bytes, 24, SizeConst);
		 return obj;
	 }
}
